<template>
  <div class="login-wrapper">
    <div class="login-box">
      <h2>登录系统</h2>
      <el-divider />
      <el-form
        style="width:80%"
        status-icon
        label-width="auto"
      >
        <el-form-item label="用户名">
          <el-input type="text" v-model="user.loginName" />
        </el-form-item>
        <el-form-item label="密码" >
          <el-input
            type="password"
            autocomplete="off"
            v-model="user.loginPwd"
          />
        </el-form-item>
        <el-form-item>
          <!-- 美化后的登录按钮 -->
          <el-button type="primary" class="custom-login-button" @click="login">
            登录
          </el-button>
          <el-button>注册</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive } from 'vue'
import axios from '../axios/index.js'
import { userStore } from '../store/UserStore.js'
import { useRouter } from "vue-router";
const store = userStore();
const router = useRouter();
const user = reactive({
  loginName: "",
  loginPwd: ""
})
function login() {
  axios
    .post("/login", `loginName=${user.loginName}&loginPwd=${user.loginPwd}`)
    .then((d) => {
      alert(JSON.stringify(d.data));
      if (d.data.code === 2000) {
        let user = d.data.data;
        store.saveUser(user);
        alert("登录成功")
        router.push("/diancai")
      } else {
        alert(d.data.msg)
      }
    })
}
</script>

<style scoped>
.login-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #f4f4f9;
}

.login-box {
  background-color: #fff;
  border-radius: 10px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  padding: 40px;
  width: 400px;
  animation: fadeIn 0.5s ease-in-out;
}

h2 {
  text-align: center;
  margin-bottom: 20px;
  color: #333;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 自定义登录按钮样式 */
.custom-login-button {
  background-color: #409eff;
  border-color: #409eff;
  color: white;
  font-size: 16px;
  font-weight: bold;
  padding: 12px 24px;
  border-radius: 8px;
  transition: background-color 0.3s ease;
}

.custom-login-button:hover {
  background-color: #66b1ff;
  border-color: #66b1ff;
}

.custom-login-button:focus {
  outline: none;
  box-shadow: 0 0 0 2px rgba(64, 158, 255, 0.2);
}
</style>